<?php

class KabKota {

    private $id;
    private $name;
    private $province;

    public function __construct($_id, $_name, $_province) {
        $this->id = $_id;
        $this->name = $_name;
        if ($_province instanceof Province) {
            $this->province = $_province;
        }
    }

    public function setId($_id) {
        $this->id = $_id;
    }

    public function getId() {
        return $this->id;
    }

    public function setName($_name) {
        $this->name = $_name;
    }

    public function getName() {
        return $this->name;
    }

    public function getProvince() {
        return $this->province;
    }

    public function setProvince($_province) {
        if ($_province instanceof Province) {
            $this->province = $_province;
        }
    }

    public function save() {
        mysql_query("insert into kabkota(name,province_id) values('$this->name'," . $this->province->getId() . ")");
    }

    public static function load($_id) {
        $result = mysql_query("select id,name,province_id from kabkota where id=$_id");
        $row = mysql_fetch_row($result);
        $kabkota = new KabKota($row[0], $row[1],Province::load($row[2]));
        return $kabkota;
    }

}

?>
